/*
	Header file
	-----------
	Stack.h

	Description:
	------------
	Template declaration for Stack data structure
	includes all method, attributes and relevent properties

 */

#ifndef _STACK_H_
#define _STACK_H_

#include "DL_List.h"

#include <iostream>
#include <stdlib.h>     // used for exit()

using namespace std;

template <class T, int size>
class Stack
{
public:
    Stack(): maxSize(size) {};		    // default constructor
    ~Stack() { myStack.Clear(); };		// destructor

    void Push(const T &item) {		    // implements PushFront of DL_List<T>
	    if (myStack.Size() == maxSize)
		    return;

	    myStack.PushFront(item);
    };
    T* Top() {						    // Peeks into 1st element
        return ((this->myStack.Size() == 0) ? NULL : this->myStack[0]);
    };
	bool Empty() { return (myStack.Size() == 0); };					// returns true - stack is empty, false otherwise
	int Size() { return myStack.Size(); };	                        // Returns the size of the stack
	void Pop(int n=1);			                                    // pops n items from stack

private:
	DL_List<T> myStack;
	int maxSize;
};

// pops n items from stack
template <class T, int size>
void Stack<T,size>::Pop(int n=1)
{
	// Remove n elements
	for ( ; (n>0) && (myStack.Size() > 0); n--)
		myStack.PopFront();
}



#endif
